<template>
  <div id="index">
    <div class="top">
      <van-swipe class="my-swipe" :autoplay="3000" indicator-color="white" height="100">
        <van-swipe-item v-for="(item, index) in images" :key="index">
          <img v-lazy="item.banner_img" :alt="item.name" :src="item.banner_img" />
        </van-swipe-item>
      </van-swipe>
      <ul>
        <li v-for="( item , index ) in nav" :key="index">
          <router-link tag="a" :to="item.path">
            <span :class="['iconfont', item.icon ,item.color]"></span>
            <b>{{ item.name }}</b>
          </router-link>
        </li>
      </ul>
    </div>
    <div class="center" v-for="item in listData" :key="item.id">
      <div class="listTitle">
        <b>{{ item.channel_info.name }}</b>
      </div>
      <myCard :cardData="item.list"></myCard>
    </div>
  </div>
</template>


<script>
import { getBanner, cartList } from "@/utils/api/api"; //接口
import myCard from "@/components/card/myCard.vue"; //组件
import { Swipe, SwipeItem } from "vant";
export default {
  components: {
    myCard,
    [Swipe.name]: Swipe,
    [SwipeItem.name]: SwipeItem,
  },
  name: "Home",
  data() {
    return {
      images: [],
      nav: [
        {
          icon: "icon-shuji",
          name: "特色课",
          color: "colorOne",
          path: "/course",
        },
        {
          icon: "icon-xiaoxi",
          name: "一对一辅导",
          color: "colorTwo",
          path: "/oto",
        },
        {
          icon: "icon-rili",
          name: "学习日历",
          color: "colorThree",
          path: "/calendar",
        },
      ],
      listData: [],
    };
  },

  created() {
    getBanner().then((res) => {
      console.log(111);
      this.images = res.data;
    });
    cartList().then((res) => {
      this.listData = res.data;
    });
  },
};
</script>


<style lang="scss" scoped>
#index {
  background-color: #eee;
  overflow: auto;
  .top {
    width: 100%;
    height: 180px;
    background-color: #eee;
    position: relative;
    box-sizing: border-box;

    .van-swipe,
    .van-swipe-item,
    img {
      width: 100%;
      height: auto;
    }

    ul {
      width: 100%;
      position: absolute;
      display: flex;
      bottom: 15px;
      justify-content: space-around;

      li {
        width: 100px;
        height: 100px;
        padding: 10px;
        border-radius: 8px;
        background-color: white;
        text-align: center;

        a {
          display: block;
          width: 100%;
          height: 100%;
          color: #000;
        }

        span {
          font-size: 40px;
        }

        .colorOne {
          color: red;
        }

        .colorTwo {
          color: #7722ff;
        }

        .colorThree {
          color: #00cc00;
        }

        b {
          display: block;
          margin-top: 15px;
          //   vert-align: middle;
        }
      }
    }
  }

  .center {
    width: 100%;
    padding: 0 10px;

    .listTitle {
      display: flex;
      width: 100%;
      height: 25px;
      margin-bottom: 10px;

      b {
        padding: 0 10px;
        line-height: 26px;
      }
    }

    .listTitle:before {
      content: "";
      display: inline-block;
      border-left: 4px solid red;
    }
  }
}
</style>